<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%
	request.setAttribute("modelConfigPath", "stock");
%>
<%@ include file="/WEB-INF/views/shared/master/contentHeader.jsp"%>
<style type="text/css">

	td input{height:21px; width:98%;border:none;}
	td{height:21px;padding: 2px 2px !important;text-align:center }
</style>	
<t:panel cssClass="panel-flat form-detailed" customBody="true" customHead="true">
    <div class="detailed-navbar-content panel-body">
    	 <div class="panel-header" style="height:60px;background-color:#FFF9ED;margin:0 auto  ">
            <label id="purchaseState" style="color:red;font-size:1.6em;margin-left:20px;margin-top:15px"><t:provider packageName="purchase" enumClassName="PurchaseState" value="${purchase.purchaseState }"/></label><label  style="font-size:1.2em;margin-left:20px">采购单号 : ${purchase.purchaseNo }</label><label style="font-size:1.2em;margin-left:20px">供应商 :  ${purchase.supplier.supplierName }	</label><label style="font-size:1.2em;margin-left:20px">采购员 : ${purchase.purchaseName }	</label><label style="font-size:1.2em;margin-left:20px">采购日期 : <fmt:formatDate value="${purchase.createDate}" type="date" dateStyle="default" pattern="YY-MM-dd HH:mm"/>	</label>				
		 </div>
        <t:form modelAttribute="inStock" action="/purchase/purchase/saveInStock" method="post" cssClass="form-horizontal">
            <div class="hide">
                <t:hidden path="inStockId"/>
                <t:hidden path="purchaseId" value='${t_purchaseId }'/>
                <t:hidden path="deleteMark"/>     
            </div>            
            
	             <div class="panel-heading" style="border-bottom-style:solid;border-width:1px">
					<h6 class="panel-title" >待入库产品清单</h6>
					<div class="heading-elements">
						<ul class="icons-list">
	                		<li><a data-action="collapse"></a></li>
	                	</ul>
	               	</div>
				 </div>
				<div class="table-responsive" style="height:210px">
				<table  class="cntable table table-bordered dataTable " >	
					<!-- <div style="margin-top:20px">
						<t:formgroup >
			                <t:label path="warehouse" cssClass="col-sm-1" />
			                <t:select2 path="warehouse" allowClear="true" placeholder="请选择仓库"  colClass="col-xs-4" />
			                <label style="text-algin:center" >本次入库数设为0表示此商品暂不入库</label>  
			               
			            </t:formgroup>	
		            </div>	 -->	
					<thead>
						<tr class="success" >
							<th style="width:70px">序号</th>
							<th style="width:120px">商品编码</th>
							<th style="width:120px">商品名称</th>
							<th style="width:120px">规格</th>
							<th style="width:120px">单位</th>
							<th style="width:120px">采购数</th>
							<th style="width:120px">已入库数</th>
							<th style="width:120px">本次入库数</th>
						</tr>
					</thead>
					<tbody >
					<c:forEach var="purchaseCollocation" items="${purchase.purchaseCollocations}" varStatus="status">
						<tr style="height:40px">
							<td>${status.index+1 }</td>
							<td  class="hide">
								<input id="ids" name="ids" value="${purchaseCollocation.id}" type="hidden">
							</td>
							<td  class="hide">
								<input id="collocationIds" name="collocationIds" value="${purchaseCollocation.collocation.collocationId}" type="hidden">
							</td>
							<td  class="hide">
								<input id="collocationIds" name="unit" value="${purchaseCollocation.cargo.unit }" type="hidden">
							</td>
							<td  class="hide">
								<input id="cargoIds" name="cargoIds" value="${purchaseCollocation.cargoId }" type="hidden">
							</td>
							<td>${purchaseCollocation.collocation.collocationNo }</td>
							<td>${purchaseCollocation.cargo.cargoName }</td>
							<td>${purchaseCollocation.collocation.propertyNameOne }/${purchaseCollocation.collocation.propertyNameTwo }</td>
							<td>${purchaseCollocation.cargo.unit }</td>
							<td class="purchaseNumber"><label>${purchaseCollocation.purchaseNumber }</label></td>
							<td class="inStockNum"><label>${purchaseCollocation.inStockNum }</label></td>						
							<td>
								<input class="inNumber" onchange="chenckNumber(this)" name="inStockNums" value="${purchaseCollocation.purchaseNumber-purchaseCollocation.inStockNum }" type="number" class="form-control " placeholder="小计">
							</td>
						</tr>
						</c:forEach>	
					</tbody>
					<tfoot></tfoot>
				</table>       
			</div>
			<div class="detailed-navbar-content panel-body">
		  		<t:formgroup>
	                <t:label path="createDate" cssClass="col-sm-1" />
	                <t:datetime2  inputGroupIcon="icon-calendar" path="createDate" colClass="col-sm-3"></t:datetime2>
	                <t:label path="operatorName" cssClass="col-sm-1" />
	                <t:input path="operatorName" colClass="col-sm-3" />
	                <t:label path="inStockNo" cssClass="col-sm-1" />
	                <t:input path="inStockNo" colClass="col-sm-3" />   
	            </t:formgroup>
  			
	            <t:formgroup>
	                <t:label path="comment" cssClass="col-sm-1" />
	               	<t:textarea  path="comment" colClass="col-md-7"/>      
	            </t:formgroup>
	  		</div>
            
        </t:form> 
        <t:panelFoot headingBtnCssClass="heading-btn pull-right-important">
			<t:button icon="icon-floppy-disk" onclick="saveData()" laddaType="progress" cssClass="btn-info" csize="sm">保存</t:button>
		</t:panelFoot>
    </div>
  
	
</t:panel>

<script type="text/javascript">
$(function(){
	randomNumber();
	var purchaseState=$("#purchaseState").text();
	
	if(purchaseState=="已入库"){
		$("#inStock").css("display","none");
		$(".inStock-footer").css("display","none");
	}
});

function chenckNumber(element){
	var purchaseNumber=$(element).parent().siblings(".purchaseNumber").find("label").text();
	var inStockNum=$(element).parent().siblings(".inStockNum").find("label").text();
	var inStockNow=$(element).val();
	
	if(inStockNow>(purchaseNumber-inStockNum)){
		$(element).val(purchaseNumber-inStockNum);
	}
	
	console.log(purchaseNumber)
}


function toVoid(id){
	
		var url = $.getVirtualPath()+"/purchase/purchase/toVoid?key="+id;
		deleteDataEx(url, searchCallback);
 
}

function saveData(lBtn){
	var num=0;
	$(".inNumber").each(function (){
		num+=$(this).val();
	})
	
	if(num==0||num<0){
		$.notify("无可入库产品!!","warning");
		return;
	}
	
	if (!$("form:first").valid()){
		return;
	}
	lBtn.start();
	$("form:first").submit();
}
function printer(inStockId){


	top.openModal("/purchase/purchase/inStockDetailPrint?key="+inStockId,"inStock_form","采购入库单打印",1200,450);
}
function randomNumber(){
	const now =new Date();
	
	var  month=now.getMonth()+1;
	var day=now.getDate();
	var hour=now.getHours();
	var minutes=now.getMinutes();
	var seconds=now.getSeconds();
    var inStockNo="IN-"+ now.getFullYear().toString() + month.toString() + day + hour + minutes + seconds+"-" + (Math.round(Math.random() * 89 + 100)).toString()
	$("#inStockNo").val(inStockNo);
	
}
</script>
<%@ include file="/WEB-INF/views/shared/base/scripts/jqueryui.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formtags.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formbuttons.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formpickers.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formstyling.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/dialog.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/notifications.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/contentFooter.jsp"%>
